package codename.carrot.bomberman;

import sheep.graphics.Image;
import codename.carrot.bomberman.AppStorage.Direction;
import codename.carrot.bomberman.models.Bomb;
import codename.carrot.bomberman.models.Boulder;
import codename.carrot.bomberman.models.CollectableItem;
import codename.carrot.bomberman.models.ItemContainer;
import codename.carrot.bomberman.models.Player.PlayerColor;
import codename.carrot.bomberman.views.widgets.BombButton;

/**
 *  A factory for creating graphics used in the game
 * @author Group A4
 * 
 */
public class BitmapFactory {
	private static Image[] explotionView = null;
	private static Image[] bombView = null;	
	private static Image boulderImage, itemContainerImage;	
	
	
	/**
	 *  Returns an image for toggle-button (used for switching between players when dead)
	 * @param direction - AppStorage.DIRECTION_LEFT or AppStorage.DIRECTION_RIGHT
	 * @return Image
	 */
	public static Image buildToggleButton(Direction direction){
		if(direction == Direction.LEFT){
			return new Image(R.drawable.toggle_left);
		} else {
			return new Image(R.drawable.toggle_right);
		}
	}
	
	/**
	 * Returns an image for the bomb-placement button used when key not pressed( {@link BombButton} )
	 * @return Image
	 */
	public static Image buildBombButtonUp(){
		return new Image(R.drawable.bomb_icon);
	}
	
	/**
	 * Returns an image for the bomb-placement button used when key is pressed( {@link BombButton} )
	 * @return Image
	 */
	
	public static Image buildBombButtonDown(){
		return new Image(R.drawable.bomb_icon_down);
	}
	
	/**
	 *  Returns an array of {@link Image} for explosion (flames)
	 * @return Image[] - array of images
	 */
	public static Image[] buildExplotionView() {
	    if(explotionView == null) {
    		explotionView = new Image[11];
    		explotionView[0] = new Image(R.drawable.explotion_1);
    		explotionView[1] = new Image(R.drawable.explotion_2);
    		explotionView[2] = new Image(R.drawable.explotion_3);
    		explotionView[3] = new Image(R.drawable.explotion_4);
    		explotionView[4] = new Image(R.drawable.explotion_5);
    		explotionView[5] = new Image(R.drawable.explotion_6);
    		explotionView[6] = new Image(R.drawable.explotion_7);
    		explotionView[7] = new Image(R.drawable.explotion_8);
    		explotionView[8] = new Image(R.drawable.explotion_9);
    		explotionView[9] = new Image(R.drawable.explotion_10);
    		explotionView[10] = new Image(R.drawable.explotion_11);
	    }
		return explotionView;
	}

	/**
	 *  Returns an array of images for {@link Bomb} (when placed on the map, awaiting explosion )
	 * @return Image[] - array of images
	 */
	public static Image[] buildBombView() {
	    if(bombView == null) {
	        bombView = new Image[4];
	        bombView[0] = new Image(R.drawable.bomb_1);
	        bombView[1] = new Image(R.drawable.bomb_2);
	        bombView[2] = new Image(R.drawable.bomb_3);
	        bombView[3] = new Image(R.drawable.bomb_2);   
	    }
		return bombView;
	}
	
	/**
	 *  Returns an image for {@link Boulder}
	 * @return Image
	 */
	public static Image buildBoulderImage() {
	    if(boulderImage == null) boulderImage = new Image(R.drawable.boulder);
	    return boulderImage;
	}

	/**
	 *  Returns an image for {@link ItemContainer}
	 * @return Image
	 */
	public static Image buildItemContainerImage() {
	    if(itemContainerImage == null) itemContainerImage = new Image(R.drawable.crate);
	    return itemContainerImage;
	}
	
	
	/**
	 *  Returns an image for a collectible item (see {@link CollectableItem} )
	 * @param type The collectible item. 
	 * @param up A boolean depicting if it is a power up or a power down.
	 * @return  The Image
	 */
	public static Image buildItemView(int type, boolean up) {
		switch (type) {
		case CollectableItem.ITEM_BOMB:
			if (up)
				return new Image(R.drawable.buff_bomb_up);
			else
				return new Image(R.drawable.buff_bomb_down);			
		case CollectableItem.ITEM_FLAME:
			if(up)
				return new Image(R.drawable.buff_explode_up);
			else
				return new Image(R.drawable.buff_explode_down);
		case CollectableItem.ITEM_SPEED:
			if(up)
				return new Image(R.drawable.buff_speed_up);
			else
				return new Image(R.drawable.buff_speed_down);
		}
		return null;
	}

	/**
	 * Set up and return an image array for animating the player.
	 * @param color The color of the player.
	 * @param direction The direction of movement to create.
	 * @return The image sequence.
	 */
	public static Image[] buildPlayerView(PlayerColor color, Direction direction) {
		Image[] image = new Image[4];
		switch (color) {
		case PURPEL:
			switch (direction) {
			case LEFT:
				image[0] = new Image(R.drawable.purpel_1_l);
				image[1] = new Image(R.drawable.purpel_2_l);
				image[2] = new Image(R.drawable.purpel_3_l);
				image[3] = new Image(R.drawable.purpel_2_l);
				return image;
			case RIGHT:
				image[0] = new Image(R.drawable.purpel_1_r);
				image[1] = new Image(R.drawable.purpel_2_r);
				image[2] = new Image(R.drawable.purpel_3_r);
				image[3] = new Image(R.drawable.purpel_2_r);
				return image;
			case DOWN:
				image[0] = new Image(R.drawable.purpel_1_d);
				image[1] = new Image(R.drawable.purpel_2_d);
				image[2] = new Image(R.drawable.purpel_3_d);
				image[3] = new Image(R.drawable.purpel_2_d);
				return image;
			case UP:
				image[0] = new Image(R.drawable.purpel_1_u);
				image[1] = new Image(R.drawable.purpel_2_u);
				image[2] = new Image(R.drawable.purpel_3_u);
				image[3] = new Image(R.drawable.purpel_2_u);
				return image;
			default:
				break;
			}
			break;
		case YELLOW:
			switch (direction) {
			case LEFT:
				image[0] = new Image(R.drawable.yellow_1_l);
				image[1] = new Image(R.drawable.yellow_2_l);
				image[2] = new Image(R.drawable.yellow_3_l);
				image[3] = new Image(R.drawable.yellow_2_l);
				return image;
			case RIGHT:
				image[0] = new Image(R.drawable.yellow_1_r);
				image[1] = new Image(R.drawable.yellow_2_r);
				image[2] = new Image(R.drawable.yellow_3_r);
				image[3] = new Image(R.drawable.yellow_2_r);
				return image;
			case DOWN:
				image[0] = new Image(R.drawable.yellow_1_d);
				image[1] = new Image(R.drawable.yellow_2_d);
				image[2] = new Image(R.drawable.yellow_3_d);
				image[3] = new Image(R.drawable.yellow_2_d);
				return image;
			case UP:
				image[0] = new Image(R.drawable.yellow_1_u);
				image[1] = new Image(R.drawable.yellow_2_u);
				image[2] = new Image(R.drawable.yellow_3_u);
				image[3] = new Image(R.drawable.yellow_2_u);
				return image;
			default:
				break;
			}
			break;
		case BLUE:
			switch (direction) {
			case LEFT:
				image[0] = new Image(R.drawable.blue_1_l);
				image[1] = new Image(R.drawable.blue_2_l);
				image[2] = new Image(R.drawable.blue_3_l);
				image[3] = new Image(R.drawable.blue_2_l);
				return image;
			case RIGHT:
				image[0] = new Image(R.drawable.blue_1_r);
				image[1] = new Image(R.drawable.blue_2_r);
				image[2] = new Image(R.drawable.blue_3_r);
				image[3] = new Image(R.drawable.blue_2_r);
				return image;
			case DOWN:
				image[0] = new Image(R.drawable.blue_1_d);
				image[1] = new Image(R.drawable.blue_2_d);
				image[2] = new Image(R.drawable.blue_3_d);
				image[3] = new Image(R.drawable.blue_2_d);
				return image;
			case UP:
				image[0] = new Image(R.drawable.blue_1_u);
				image[1] = new Image(R.drawable.blue_2_u);
				image[2] = new Image(R.drawable.blue_3_u);
				image[3] = new Image(R.drawable.blue_2_u);
				return image;
			default:
				break;
			}
			break;
		case ORANGE:
			switch (direction) {
			case LEFT:
				image[0] = new Image(R.drawable.orange_1_l);
				image[1] = new Image(R.drawable.orange_2_l);
				image[2] = new Image(R.drawable.orange_3_l);
				image[3] = new Image(R.drawable.orange_2_l);
				return image;
			case RIGHT:
				image[0] = new Image(R.drawable.orange_1_r);
				image[1] = new Image(R.drawable.orange_2_r);
				image[2] = new Image(R.drawable.orange_3_r);
				image[3] = new Image(R.drawable.orange_2_r);
				return image;
			case DOWN:
				image[0] = new Image(R.drawable.orange_1_d);
				image[1] = new Image(R.drawable.orange_2_d);
				image[2] = new Image(R.drawable.orange_3_d);
				image[3] = new Image(R.drawable.orange_2_d);
				return image;
			case UP:
				image[0] = new Image(R.drawable.orange_1_u);
				image[1] = new Image(R.drawable.orange_2_u);
				image[2] = new Image(R.drawable.orange_3_u);
				image[3] = new Image(R.drawable.orange_2_u);
				return image;
			default:
				break;
			}
			break;
		}
		return image;
	}
}
